# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=miniupnpc
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=2.1
pkgrel=1
pkgdesc="A small UPnP client library/tool to access Internet Gateway Devices (mingw-w64)"
arch=('any')
url="http://miniupnp.free.fr"
license=('BSD')
options=('staticlibs')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-python3")
source=(https://miniupnp.tuxfamily.org/files/${_realname}-${pkgver}.tar.gz)
sha256sums=('e19fb5e01ea5a707e2a8cb96f537fbd9f3a913d53d804a3265e3aeab3d2064c6')

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  cp -rf ${_realname}-${pkgver} build-${MINGW_CHOST}
  #mkdir -p build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}
  
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DUPNPC_BUILD_SHARED=ON \
    -DUPNPC_BUILD_STATIC=ON \
    .

  make
  
  for pyt in 2 3; do
    msg "Build Python${pyt} extension..."
    MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python${pyt} setupmingw32.py build
  done
}

package() {
  cd build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install

  install -Dm644 ${srcdir}/${_realname}-${pkgver}/man3/miniupnpc.3 \
    "${pkgdir}${MINGW_PREFIX}/share/man/man3/miniupnpc.3"
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
    
  for pyt in 2 3; do
    msg "Install Python${pyt} extension..."
    MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python${pyt} setupmingw32.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}"
  done
}